/*
 * Copyright© 2003-2019 浙江汇信科技有限公司, All Rights Reserved.
 */
package com.icinfo.cloud.provider.punish.common.electricsent.controller;

import com.icinfo.cloud.common.core.page.PageResponse;
import com.icinfo.cloud.provider.common.constant.Constant;
import com.icinfo.cloud.provider.punish.common.electricsent.dto.DocumentSendPageRequest;
import com.icinfo.cloud.provider.punish.common.electricsent.dto.DocumentSendPageResponse;
import com.icinfo.cloud.provider.punish.common.electricsent.dto.DocumentSendRecordQueryDto;
import com.icinfo.cloud.provider.punish.common.electricsent.dto.DocumentSendRecordSaveDto;
import com.icinfo.cloud.provider.punish.common.electricsent.service.IDocumentSendRecordService;
import com.icinfo.cloud.provider.punish.common.electricsent.vo.DocumentSendRecordVo;
import com.icinfo.framework.common.web.Result;
import com.icinfo.framework.core.web.BaseController;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * 描述: 文书发送记录 document_send_record 对应的Controller类.<br>
 *
 * @author framework generator
 * @date 2022年02月18日
 */
@RestController
@RefreshScope
@RequestMapping("/punish/common/electricsent/sendRecord")
@Slf4j
public class DocumentSendRecordController extends BaseController {
    @Resource
    private IDocumentSendRecordService documentSendRecordService;

    /**
     * 【V1.0.0】描述：保存文书发送记录
     *
     * @param saveDto {@link DocumentSendRecordSaveDto}
     * @return {@link Result <String>} 保存结果
     * @author xiangyuyu
     * @date 2022-02-16 16:02
     */
    @PostMapping("/saveDocumentSendRecord")
    @ApiOperation(value = "【V1.0.0】描述：保存文书发送记录", httpMethod = "POST")
    public Result<String> saveDocumentSendRecord(@RequestBody @Validated DocumentSendRecordSaveDto saveDto) {
        Map<String,Object> resultMap = documentSendRecordService.saveDocumentSendRecord(saveDto);
        if("true".equals(resultMap.get("success").toString())){
            return Result.success(resultMap.get("msg").toString());
        }else {
            return Result.error(resultMap.get("msg").toString());
        }
    }


    /**
     * 【V1.0.0】描述：获取文书发送记录列表
     *
     * @param queryDto {@link DocumentSendRecordQueryDto}
     * @return {@link Result<List<DocumentSendRecordVo>>} 文书发送记录列表
     * @author xiangyuyu
     * @date 2022-02-16 16:02
     */
    @PostMapping("/getDocumentSendRecordList")
    @ApiOperation(value = "【V1.0.0】描述：获取文书发送记录列表", httpMethod = "POST")
    public Result<List<DocumentSendRecordVo>> getDocumentSendRecordList(@RequestBody @Validated DocumentSendRecordQueryDto queryDto) {
        List<DocumentSendRecordVo> list = documentSendRecordService.getDocumentSendRecordList(queryDto);
        return Result.success(Constant.STRING_GET_SUCCESS, list);
    }

    /**
     * 【V1.0.0】描述：根据唯一标识查询文书发送记录
     *
     * @param id 唯一标识
     * @return {@link Result<DocumentSendRecordVo>} 文书发送记录
     * @author xiangyuyu
     * @date 2022-02-16 16:02
     */
    @PostMapping("/getDocumentSendRecord")
    @ApiOperation(value = "【V1.0.0】描述：根据唯一标识查询文书发送记录", httpMethod = "POST")
    public Result<DocumentSendRecordVo> getDocumentSendRecord(@RequestParam String id) {
        DocumentSendRecordVo vo = documentSendRecordService.getDocumentSendRecord(id);
        return Result.success(Constant.STRING_GET_SUCCESS, vo);
    }

    /**
     * 电子送达记录分页查询
     *
     * @param queryDto {@link DocumentSendPageRequest}
     * @return {@link Result<List<DocumentSendPageResponse>>} 电子送达记录列表
     * @author yehaufei
     * @date 2022-11-28
     */
    @PostMapping("/getDocumentSendPage")
    @ApiOperation(value = "电子送达记录分页查询", httpMethod = "POST")
    public Result<PageResponse> getDocumentSendPage(@RequestBody DocumentSendPageRequest queryDto) {
        List<DocumentSendPageResponse> list = documentSendRecordService.getDocumentSendList(queryDto);
        return Result.success(Constant.STRING_GET_SUCCESS, new PageResponse(list));
    }
}
